#include <windows.h>

#include "console_client_application.h"
#include "response_listener.h"
#include "header_creater.h"

#include <ballade/network.h>

#pragma comment(lib, "../../lib/ballade/smartclient.lib")
#pragma comment(lib, "../../lib/ballade/util.lib")
#pragma comment(lib, "../../lib/ballade/network.lib")

ConsoleClientApplication::ConsoleClientApplication()
{
	Logger_.setLevel(Ballade::Util::Logger::Level::DEBUG_);
}

ConsoleClientApplication::~ConsoleClientApplication()
{
	Logger_.close();
}

void ConsoleClientApplication::run()
{
 	ResponseListener responseListener("1000");
 	_client.addListener(&responseListener);
	HeaderCreater headerCreater;
	_client.setHeaderCreater(&headerCreater);

	_client.setIPAddress("192.168.1.161");
	_client.setPort(1316);

	try
	{
		_client.connect();
		_client.send("1000", "Hello Yanny!");
	} 
	catch(Ballade::Network::SocketError &e)
	{
		Logger_.error("ConsoleClientApplication(run) - %s", e.what());
	}
	
	while(_client.isConnected())
	{
		Sleep(1000);
	}
	_client.close();
}

Ballade::Util::Logger& ConsoleClientApplication::Logger_ = Ballade::Util::Logger::getInstance();

int main()
{
	ConsoleClientApplication app;
	app.run();

	return 0;
}